<#import "/admin/_layout.html" as layout>
<@layout.header "规格编辑"></@layout.header>
<@layout.body>
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-left">
                        <li class="breadcrumb-item"><a href="#">规格</a></li>
                        <li class="breadcrumb-item active">新增</li>
                    </ol>
                </div>
            </div>
        </div>
    </div>
    <section class="content">
        <div class="container-fluid">
            <div class="card card-default">
                <form id="myForm" method="POST" action="/admin/product/spec/doSave" ok="/admin/product/spec/list">
                    <input type="hidden" name="id" value="${(spec.id)!}">
                    <div class="card-body">
                        <div class="form-group">
                            <label for="roleName">规格名称</label>
                            <input type="text" name="specName" class="form-control" id="specName" placeholder="请输入规格名称" value="${(spec.specName)!}">
                        </div>
                        <div class="form-group">
                            <label class="control-label">摘要</label>
                            <textarea rows="3" class="form-control"
                                              placeholder="..."
                                              name="specMemo">${(spec.specMemo)!}</textarea>
                        </div>

                        <div class="box box-solid" style="width: 200px;">
                            <div class="box-header with-border ">
                                <label for="thumbnail">图标</label>
                            </div>
                            <div class="box-body no-padding">
                                <img src="/static/${(spec.specIcon)!'/img/default.jpg'}"
                                     style="width: 100%;height: 200px"
                                     id="thumbnail">
                                <input type="hidden" value="${(spec.specIcon)!}" name="specIcon" id="articleThumbnail">
                            </div>
                            <div class="box-footer">
                                <button type="button" class="btn-image-browser btn btn-default btn-sm "
                                        for-src="thumbnail"
                                        for-input="articleThumbnail">选择图片
                                </button>
                                <a href="javascript:;" style="padding-left: 15px" id="removeThumbnail">移除</a>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="roleName">排序</label>
                            <input type="number" name="sortNum" class="form-control" id="sortNum" placeholder="请输入规格排序" value="${(spec.sortNum)!}">
                        </div>

                        <div class="form-group">
                            <label for="spec_values_table">规格值</label>
                            <div class="col-sm-8">

                                <table class="table">
                                    <tbody id="spec_values_table">

                                    <#if specValueList??>
                                        <#list specValueList as specValue>
                                            <tr>
                                                <input type="hidden" name="specValueIds" value="${(specValue.id!)}">
                                                <td><input type="input" style="display: inline" name="specValueNames" class="form-control" value="${(specValue.specValueName)!}" placeholder="规格值名称">&nbsp;</td>
                                                <td><input type="number" style="display: inline" name="specValueSortNums" class="form-control" value="${(specValue.sortNum)!}" placeholder="排序">&nbsp;</td>
                                                <td></td>
                                            </tr>
                                        </#list>
                                    <#else>
                                        <tr>
                                            <input type="hidden" name="specValueIds" value="">
                                            <td><input type="input" style="display: inline" name="specValueNames" class="form-control" value="" placeholder="规格值名称">&nbsp;</td>
                                            <td><input type="number" style="display: inline" name="specValueSortNums" class="form-control" value="" placeholder="排序">&nbsp;</td>
                                            <td></td>
                                        </tr>
                                    </#if>
                                    </tbody>
                                </table>

                            </div>

                        </div>

                        <div class="form-group">

                            <label class="col-sm-2 control-label"></label>
                            <div class="clo-sm-8">
                                <span id="add-spec-value" style="cursor: pointer"><i class="fa fa-fw fa-plus"></i> 新增规格值</span>
                            </div>

                        </div>

                    </div>
                    <div class="card-footer">
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </section>
    <script type="text/html" id="spec_value_tpl">
        <tr>
            <input type="hidden" name="specValueIds" value="">
            <td><input type="input" style="display: inline" name="specValueNames" class="form-control" value="" placeholder="规格值名称"></td>
            <td><input type="number" style="display: inline" name="specValueSortNums" class="form-control" value="" placeholder="排序"></td>
            <td><a class="del-spec_value-item" href="javascript:void(0)" onclick="delSpecValueItem(this)">删除</a></td>
        </tr>
    </script>
</@layout.body>
<@layout.script>
    <script>
        $(function () {
            submitForm({
                specName: { required: true}
            },{
                specName: {required: "请输入规格名称"}
            })
        });

        $("#add-spec-value").click(function(){
            $("#spec_values_table").append($("#spec_value_tpl").html())
        })

        function delSpecValueItem(obj){
            layer.confirm('确认要删除吗？', {
                btn : [ '确定', '取消' ]//按钮
            }, function(index) {
                layer.close(index);
                $(obj).parent().parent().remove()
            });
        }
    </script>
</@layout.script>